home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODF-Interest Archive / July 96 / Subtlety with FW_OStorageUnitSi < prev    next >
Encoding:
Internet Message Format  |  1996-07-30  |  1.7 KB  |  [TEXT/ttxt]

  1. Subject:     Subtlety with FW_OStorageUnitSink and ODStorageUnit
  2. Sent:        7/21/96 1:18 AM
  3. Received:    7/22/96 10:48 AM
  4. From:        Hutchings, Richard B. "Brad", brad@hutchings-software.com
  5. Reply-To:    ODF Interest, ODF-Interest@CILabs.ORG
  6. To:          OpenDoc Development Framework Discussion List, ODF-Interest@CILabs.
  7.  
  8. Following is a subtlety I ran into this evening dealing with
  9. FW_OStorageUnitSink and ODStorageUnit. Here's a working snippet.
  10.  
  11.     void CyberItemAction::ExternalizeToStream(
  12.                         Environment*        ev,
  13.                         FW_CWritableStream&    stream    )
  14.     {
  15.         FW_OStorageUnitSink*    sink =
  16.                             (FW_OStorageUnitSink*) stream.GetSink();
  17.         ODStorageUnitView*        view = sink->GetStorageUnitView(ev);
  18.         ODStorageUnit*            storage = view->GetStorageUnit(ev);
  19.  
  20.         fCyberItem->StreamToStorageUnit(ev, storage);
  21.     
  22.         ODULong offset = storage->GetOffset(ev);
  23.         sink->SetPosition(ev, offset);
  24.  
  25.         stream << ...
  26.     }                                                                
  27. First, I had to convert to the storage unit because that's what Cyberdog
  28. expects in CyberItem::StreamToStorageUnit. 
  29.  
  30. Second, notice that when you write directly to the storage unit, the stream
  31. gets out of date, and that you have to set its position.
  32.  
  33. Third, notice that I don't use a FW_PStorageUnitSink because it would
  34. clobber the stream when ~FW_PStorageUnitSink is called on exit.
  35.  
  36. This could be helped by a "smarter" FW_PStorageUnitSink that had an
  37. "operator ODStorageUnit*" method which would set a flag in the
  38. FW_OStorageUnitSink telling it to update its position the next time it's
  39. accessed from a stream.
  40.  
  41. Brad
  42.  
  43. <mailto: "Brad Hutchings" brad@hutchings-software.com>
  44. <http://www.hutchings-software.com>
  45.  
  46. Ask me about:
  47.     Hutchings Software's Rapid-I(tm) Button
  48.     Hutchings Software's Essential Strips(tm)
  49.  
  50.  
  51.